handling errors in javascript